// pages/end/index.js
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selected: 0,
    color: "#000",
    selectedColor: "#40a3f8",
    list: [{
      pagePath: "/packageA/pages/end/index",
      iconPath: "/images/home-a.png",
      selectedIconPath: "/images/home-a-v.png",
      text: "陪诊"
    }, {
      pagePath: "/packageA/pages/order/index",
      iconPath: "/images/order-a.png",
      selectedIconPath: "/images/order-a-v.png",
      text: "订单"
    }, {
      pagePath: "/packageA/pages/user/index",
      iconPath: "/images/user-a.png",
      selectedIconPath: "/images/user-a-v.png",
      text: "我的"
    }],
    imgUrls: [],
    indicatorDots: false, //小点
    indicatorColor: "white", //指示点颜色
    activeColor: "coral", //当前选中的指示点颜色
    autoplay: true, //是否自动轮播
    interval: 3000, //间隔时间
    duration: 1000, //滑动时间
    show:false,
    showI:true,
    pList:[],
    helpList:[],
    content:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getSwiper();
    this.getReceive();
    this.getHelp()
  },
    // 获取轮播图
    getSwiper(){
      let _this = this;
      App._get('service_category/banner', {
      }, result => {
        // 设置顶部导航栏栏
        // _this.setPageBar(result.data.page);
        _this.setData({
          imgUrls:result.data.list
        });
        // 回调函数
      });
  
    },
    navigateToDetail(e) {
      console.log(e)
      let order_id = e.currentTarget.dataset.id;
      // let status = e.currentTarget.dataset.status;
      // if(status=='已取消'){
      //   console.log('已取消')
      // }else{
         wx.navigateTo({
          url: '/packageA/pages/end/detail/index?order_id=' + order_id
        });
      // }
      // console.log(e)
     
    },
    // 获取公告
    getHelp(){
      let _this = this;
      App._get('wxapp/help', {
      }, result => {
        // 设置顶部导航栏栏
        // _this.setPageBar(result.data.page);
        _this.setData({
          helpList:result.data.list
        });
        // 回调函数
      });
    },
    


    // 接单池
    getReceive(){
      let _this = this;
      App._get('order/receive', {
      }, result => {
        // 设置顶部导航栏栏
        // _this.setPageBar(result.data.page);
        _this.setData({
          pList:result.data.list.data
        });
        console.log(result,_this.data.pList)
        // 回调函数
      });
    },

    handleAnn(e) {
      
      console.log(123)
      this.setData({
        show: true,
        content:e.currentTarget.dataset.content
      })
    },
    handleClose() {
      this.setData({
        show: false
      })
    },
    handleCloseI() {
      this.setData({
        showI: false
      })
      wx.setStorageSync('showI', 'true')
    },

    receivedOrder(e){
      console.log(e.currentTarget.dataset.id)
      let _this = this;
      App._get('order/received', {
        order_id:e.currentTarget.dataset.id
      }, result => {
        // 设置顶部导航栏栏
        // _this.setData({
        //   p_list:result.data.list.data
        // });
        // console.log(result,_this.data.p_list)
        wx.showToast({
          title: '接单成功',
        })
        _this.getReceive();
        // 回调函数
      });
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let showII=wx.getStorageSync('showI')
    if(showII){
      this.setData({
        showI:false
      })
      console.log(111)
    }else {
      this.setData({
        showI:true
      })
    }
    console.log(wx.getStorageSync('showI'),this.data.showI,111)
    this.getReceive();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },
  switchTab(e) {
    console.log("执行跳转",e);
    const data = e.currentTarget.dataset
    const url = data.path
    // wx.switchTab({url})
    wx.reLaunch({
      url: url,
    })
    this.setData({
      selected: data.index
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})